<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
    <style>
        .bar{
            width: 200px;
            height: 10px;
            border: 1px solid #ccc;
            margin-bottom: 10px;
        }
        .bar .bar_inner{
            background-color: red;
            height: 100%;
        }
    </style>
</head>
<body>
    <div id="app">
        <div class="bar">
            <div class="bar_inner" :style="{width:lifeFun}"></div>
        </div>
        <img :src="imgurl" alt="" width="200">
        <div>
            <button @click="punch" v-show="!isGameOver">给他一拳</button>
            <button @click="again" v-show="isGameOver">重来</button>
        </div>
      
    </div>
    <script>
        new Vue({
            el:'#app',
            data(){
                return{
                    isGameOver:false,
                    life:100,
                    imgurl:'./images/lufei.webp'
                }
            },
            methods: {
                punch(){
                    this.life-=10
                    if(this.life<=0){
                        this.isGameOver = true
                        this.imgurl = './images/over.webp'
                    }
                },
                again(){
                    this.isGameOver = false
                    this.life = 100
                    this.imgurl = './images/lufei.webp'
                }
            },
            computed:{
                lifeFun(){
                    return this.life+'%'
                }
            }
        })
    </script>
</body>
</html>